fix(opentelemetry): Add conditional browser export to avoid node deps#20556
fix(opentelemetry): Add conditional browser export to avoid node deps#20556
Conversation
size-limit report 📦
|
4e32f21 to
3924a95
Compare
isaacs
left a comment
There was a problem hiding this comment.
LGTM! Minor possible safety improvement suggestion, but mostly theoretical.
| "types": "./build/types/index.d.ts", | ||
| "default": "./build/esm/index.js" | ||
| }, | ||
| "browser": { |
There was a problem hiding this comment.
Since we're specifying browser here, it might be safer to put it above node, just to ensure that anything that claims to support this (even if it does so with weird shims etc) can pick up the browser one first.
There was a problem hiding this comment.
I wasn't 100% sure about this (and still am not 🤔 ) my thinking for this was that node is def. the main target here, and I want to avoid somebody who has a node target not getting this. IMHO that's more important than somebody who has node & browser targets not getting the node stuff - I'd say it's reasonable that if your targets include node, you get the variant with the node import 😅 but we can always revisit the order if this turns out to be problematic!
We accidentally added a
nodedependency to an export fromopentelemetrypackage, leading to problems for users using this in a browser environment.This PR adds conditional exports to the opentelemetry package, where for
browsertargets we have stubs for the node-only thing. This should generally work the same as before, but stop failing builds in browser envs.I had to adjust browser integration tests for this a bit, as they did some unnecessary aliasing which prevented webpack from using normal conditional exports. We are simply doing less now and doing regular dependency resolution which should work as expected (hopefully).